#include <iostream>
#include <vector>
using namespace std;

void dfs(vector<vector<int>> &adj, vector<bool> &visited, int node) {
    if (visited[node]) {
        return;
    }

    visited[node] = true;
    cout << node << " ";
    for (int n : adj[node]) {
        dfs(adj, visited, n);
    }
}

void dfs_print(vector<vector<int>> adj, int start) {
    int m = adj.size();
    vector<bool> visited(m, false);
    dfs(adj, visited, start);
}

int main() {
    vector<vector<int>> adj = {
        {1, 2, 3},
        {0, 2},
        {0, 4},
        {0, 4},
        {2, 3}
    };
    dfs_print(adj, 0);
    return 0;
}